package com.itheima.controller;

import com.itheima.manager.SoulTestAdminManager;
import com.itheima.domain.db.SoulPaper;
import com.itheima.domain.vo.SoulQuestionVo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AdminController {
    @Autowired
    private SoulTestAdminManager soulTestAdminManager;

    //查询所有试题列表
    @GetMapping("/soulTest")
    public List<SoulPaper> findTestSoulList() {
        return soulTestAdminManager.findTestSoulList();
    }

    //根据试题id查询试题详细信息
    @GetMapping("/soulQuestion")
    public List<SoulQuestionVo2> findSoulQuestionListBySid(String sid) {
        return soulTestAdminManager.findSoulQuestionListBySid(sid);
    }


    //根据 问题id 删除问题
    @DeleteMapping("/soulQuestion")
    public String deleteSoulQuestion(String soulQuestionId) {
        return soulTestAdminManager.deleteSoulQuestionById(soulQuestionId);
    }

    //根据问题id找问题
    @GetMapping("/soulQuestionById")
    public SoulQuestionVo2 findSoulQuestionListById(String id) {
        return soulTestAdminManager.findSoulQuestionListById(id);
    }
    //根据试题id添加问题
    @PostMapping("/soulQuestion")
    public String addSoulQuestion(@RequestBody SoulQuestionVo2 soulQuestionVo){
        String soulTestId =  soulQuestionVo.getId();
        return soulTestAdminManager.addSoulQuestion(soulTestId,soulQuestionVo);
    }
    //根据 问题id 修改问题
    @PutMapping("/soulQuestion")
    public Long updateSoulQuestion(@RequestBody SoulQuestionVo2 soulQuestionVo){
        System.out.println(soulQuestionVo);
        return soulTestAdminManager.updateSoulQuestionById(soulQuestionVo);
    }
}